using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using HengTong.Services;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using TiaoTaoHelper.Wtm.Services;
using WalkingTec.Mvvm.Core.Support.Quartz;

namespace HengTong.Tasks;

/// <summary>
/// 清洗物料
/// </summary>
[Display(Name = "清洗物料", Description = "清洗物料")]
[QuartzRepeat(0, 0,false, 10)]
public class CleanMaterialTask : BaseTask<CleanMaterialTask>
{
    protected override async Task<bool> ExecuteStart()
    {
        try
        {
            var scope = Wtm.ServiceProvider.CreateScope();
            var service = scope.ServiceProvider.GetRequiredService<DataSyncService>();
            Logger.LogInformation("开始执行清洗物料任务");
            await service.CleanMaterial(10);
            Logger.LogInformation("清洗物料任务执行完成");
            return true;
        }
        catch (System.Exception ex)
        {
            Logger.LogError($"清洗物料任务执行失败: {ex.Message}");
            return false;
        }
    }
}